<template>
    <!-- 印章管理 -->
    <div class="sealAdmin">
        <div class="header"></div>
        <div class="mainpadding">
            <div class="flexbetween">
                <span class="titletext">我的印章</span>
                <div>
                    <el-button type="primary" size="small" @click="sealapply">印章申请</el-button>
                    <!-- <el-button size="small">创建作废章</el-button> -->
                </div>
            </div>
            <div class="flexleft flex_wrap">
                <div class="flexcenter itembox_father margin-top1 boxshadow" v-for="item in dataAll.personal"
                    :key="item.sealId">
                    <div class="itembox">
                        <div class="yqy_lable">已启用</div>
                        <div class="flexcenter">
                            <img :src="item.sealImg" alt="" class="seal_img">
                        </div>
                        <div class="tabtext flexbetween margin-top3">
                            <div v-show="!item.editinfo">{{ item.sealName }}</div>
                            <el-input v-show="item.editinfo" :autofocus="item.editinfo" v-model="item.editmsg"
                                placeholder="请输入内容" size="small" style="width:140px" @blur="edititem(item)"></el-input>
                            <el-dropdown class="flexright pointer" @command="handleCommand($event, item)">
                                <span class="el-dropdown-link">...</span>
                                <el-dropdown-menu slot="dropdown">
                                    <el-dropdown-item command="a">修改名称</el-dropdown-item>
                                    <el-dropdown-item command="b">删除</el-dropdown-item>
                                </el-dropdown-menu>
                            </el-dropdown>
                        </div>
                        <!-- <div class="tabtext margin-top hui xiankuan pointer"
                            title="印章编号：5958ae6e-3dfa-4e0c-bb97-c38ce9884283">印章编号：5958ae6e-3dfa-4e0c-bb97-c38ce9884283
                        </div>
                        <div class="tabtext margin-top hui">创建日期：20210-02-02</div> -->
                    </div>
                </div>
            </div>
            <div class="margin-top3"></div>
            <hr>
            <div v-for="item in dataAll.enterprise" :key="item.enterpriseId">
                <div class="flexbetween margin-top3">
                    <span class="titletext">{{ item.subjectName }}</span>
                    <div>
                        <el-button type="primary" v-if="item.isAdmin==1" size="small" @click="manageevent(item)">管理</el-button>
                    </div>
                </div>
                <div class="flexleft flex_wrap">
                    <div class="flexcenter itembox_father margin-top1 boxshadow" v-for="ite in item.list" :key="ite.sealId">
                        <div class="itembox">
                            <div class="yqy_lable">已启用</div>
                            <div class="flexcenter">
                                <img :src="ite.sealImg" alt="" class="seal_img">
                            </div>
                            <div class="tabtext margin-top3 xiankuan">{{ ite.sealName }}</div>
                            <!-- <div class="tabtext margin-top hui xiankuan pointer"
                            title="印章编号：5958ae6e-3dfa-4e0c-bb97-c38ce9884283">
                            印章编号：5958ae6e-3dfa-4e0c-bb97-c38ce9884283</div>
                        <div class="tabtext  margin-top hui">创建日期：20210-02-02</div> -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { userEnterpriseSealList, getUpUserEnterpriseSeal,getDelUserEnterpriseSeal } from "@/api/userinfo"
import Cookies from 'js-cookie'//获取cookies的信息

export default {
    inject: ['closeloading'],
    data() {
        return {
            pararms: {
                signEnterpriseId: "",
                userId: Cookies.get('admin_id')
            },
            dataAll: {}
        }
    },
    mounted() {
        this.getseal()
    },
    methods: {
        getseal() {
            let _this=this
            userEnterpriseSealList(this.pararms).then(res => {
                _this.closeloading()
                res.result.personal.forEach(item => {
                    this.$set(item, "editinfo", false)
                    this.$set(item, "editmsg", item.sealName)
                })
                this.dataAll = res.result
            })
        },
        // 修改印章名称
        edititem(item) {
            if (item.editmsg == "") {
                item.editinfo = false
                return false
            } else {
                //此处走修改印章名称接口
                item.editinfo = false
                getUpUserEnterpriseSeal({
                    sealName: item.editmsg,
                    id:item.sealId
                }).then(res => {
                    if (res.code == 200) {
                        this.$message.success(res.message)
                        item.sealName = item.editmsg
                    } else {
                        this.$message.warning(res.message)
                    }
                }).catch(err => {
                    this.$message.warning(err.message)
                })
            }
        },
        handleCommand(e, item) {
            if (e == 'b') {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    center: true
                }).then(() => {
                    this.delseal(item)
                    
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            } else {
                item.editinfo = true
            }
        },
        // 印章申请
        sealapply() {
            this.$router.push({ path: "/admin/addSealAdmin" },()=>{})
        },
        // 删除印章
        delseal(item){
            getDelUserEnterpriseSeal(item.sealId).then(res => {
                if (res.code == 200) {
                    this.$message.success(res.message)
                    this.getseal()
                } else {
                    this.$message.warning(res.message)
                }
            }).catch(err => {
                this.$message.warning(err.message)
            })
        },
        // 管理印章
        manageevent(item) {
            this.$router.push({ path: "/business/sealAdminBusiness", query: { id: item.enterpriseId } },()=>{})
        }
    }
}
</script>

<style lang="scss" scoped>
.sealAdmin{
    overflow-y: scroll;
}
.header {
    height: 50px;
    border-bottom: 1px solid #e4e4e4;
    line-height: 50px;
    padding-left: 30px;
}

.itembox_father {
    width: 13.1%;
    padding: 0 5px;
}

.itembox {
    width: 100%;
    border: 1px solid rgba(0, 0, 0, .1);
    height: 240px;
    position: relative;
    padding: 30px 10px 30px 10px;
    box-sizing: border-box;
}

.yqy_lable {
    background-color: #e7f7ea;
    padding: 5px 10px;
    font-size: 12px;
    color: #15ad31;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
}

.seal_img {
    width: 120px;
    height: 120px;
}

.xiankuan {
    width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.margin-top {
    margin-top: 5px;
}
</style>